﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.NewOperator"/>.
    /// </summary>
    public abstract class NewOperatorVM : ArgumentsOperatorVM
    {
        #region /* FIELDS */

        protected InitializerVM _initializerVM;

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.NewOperator"/>.
        /// </summary>
        protected NewOperatorVM(NewOperator newOperator, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(newOperator, dictionary)
        {
            _initializerVM = (InitializerVM)CreateVM(newOperator.Initializer, false, dictionary);
        }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.NewOperator"/> model.
        /// </summary>
        public NewOperator NewOperator
        {
            get { return (NewOperator)CodeObject; }
        }

        /// <summary>
        /// Optional initializer.
        /// </summary>
        public InitializerVM Initializer
        {
            get { return _initializerVM; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        protected override void RenderInitializer(CodeRenderer renderer, RenderFlags flags)
        {
            if (_initializerVM != null)
                _initializerVM.Render(renderer, flags | RenderFlags.PrefixSpace);
        }

        public override void RenderVisible(CodeRenderer renderer, RenderFlags flags)
        {
            base.RenderVisible(renderer, flags);
            if (_initializerVM != null)
                _initializerVM.RenderVisible(renderer, flags);
        }

        public override void UnRender()
        {
            if (_initializerVM != null)
                _initializerVM.UnRender();
            base.UnRender();
        }

        #endregion
    }
}
